package member;

import member.Member;

import java.io.IOException;
import shared.PMF;

import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.jdo.PersistenceManager;
import javax.jdo.Transaction;

public class StockMemberServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static final String nextJSP = "/mem/editMem01.jsp";

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {
		response.setContentType("text/html;charset=BIG5");
		request.setCharacterEncoding("BIG5");
		
		Long memberID = Long.parseLong(request.getParameter("id"));
		String nickName = request.getParameter("nickName");
		PersistenceManager pm = PMF.get().getPersistenceManager();
		Transaction tx = pm.currentTransaction();
		
		try{
			tx.begin();
			Member p = pm.getObjectById(Member.class, memberID);
		    p.stock(nickName);
		    pm.makePersistent(p);
		    tx.commit();
		} finally {
            if (tx.isActive()) {
                tx.rollback();
            }
		    pm.close();
		}

		response.sendRedirect(nextJSP);
		
	}//doGet
	public void doPost(HttpServletRequest request, HttpServletResponse response) 
	throws IOException, ServletException{
		doGet(request, response);
	}
}
